package com.canaan.business.controller.pc.bill;

import com.canaan.business.domain.bill.PurchaseReturnBillDetail;
import com.canaan.business.domain.vo.PurchaseReturnBillDetailVo;
import com.canaan.business.service.bill.IPurchaseReturnBillDetailService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购退货单据明细Controller
 *
 * @author ruoyi
 * @date 2023-03-13
 */
@Api(tags = "采购退货单据明细")
@RestController
@RequestMapping("/bill/purchaseReturnDetail")
public class PurchaseReturnBillDetailController extends BaseController {
    @Resource
    private IPurchaseReturnBillDetailService purchaseReturnBillDetailService;

    /**
     * 查询采购退货单据明细列表
     */
    @ApiOperation(value = "查询采购退货单据明细列表")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseReturnBillDetail purchaseReturnBillDetail) {
        startPage();
        List<PurchaseReturnBillDetailVo> list = purchaseReturnBillDetailService.selectPurchaseReturnBillDetailListPageDatas(purchaseReturnBillDetail);
        return getDataTable(list);
    }

    /**
     * 导出采购退货单据明细列表
     */
    @ApiOperation(value = "导出采购退货单据明细列表")
    @Log(title = "采购退货单据明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseReturnBillDetail purchaseReturnBillDetail) {
        List<PurchaseReturnBillDetail> list = purchaseReturnBillDetailService.selectPurchaseReturnBillDetailList(purchaseReturnBillDetail);
        ExcelUtil<PurchaseReturnBillDetail> util = new ExcelUtil<PurchaseReturnBillDetail>(PurchaseReturnBillDetail.class);
        util.exportExcel(response, list, "采购退货单据明细数据");
    }

    /**
     * 获取采购退货单据明细详细信息
     */
    @ApiOperation(value = "获取采购退货单据明细详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(purchaseReturnBillDetailService.selectPurchaseReturnBillDetailById(id));
    }

    /**
     * 新增采购退货单据明细
     */
    @ApiOperation(value = "新增采购退货单据明细")
    @Log(title = "采购退货单据明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseReturnBillDetail purchaseReturnBillDetail) {
        return toAjax(purchaseReturnBillDetailService.insertPurchaseReturnBillDetail(purchaseReturnBillDetail));
    }

    /**
     * 修改采购退货单据明细
     */
    @ApiOperation(value = "修改采购退货单据明细")
    @Log(title = "采购退货单据明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseReturnBillDetail purchaseReturnBillDetail) {
        return toAjax(purchaseReturnBillDetailService.updatePurchaseReturnBillDetail(purchaseReturnBillDetail));
    }

    /**
     * 删除采购退货单据明细
     */
    @ApiOperation(value = "删除采购退货单据明细")
    @Log(title = "采购退货单据明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(purchaseReturnBillDetailService.deletePurchaseReturnBillDetailByIds(ids));
    }
}
